package authoritah.ui.eventtype;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import authoritah.db.EventType;


public class EventTypeModel extends AbstractTableModel {
	
	private ArrayList<EventType> displayList;
	
	public EventTypeModel(ArrayList<EventType> membersToDisplay)
	{
		super();
		displayList = new ArrayList<EventType>(membersToDisplay); // new copy to break refs.
	}

	public String getColumnName(int column) {
		switch (column) {
		case 0:
			return "Id";
		case 1:
			return "Name";
		}
		return ""; // should never get here
	}
	
	public int getColumnCount() {
		return 2;
	}

	public Object getValueAt(int row, int column) {
		EventType eventType = displayList.get(row);
		switch(column)
		{
		case 0:
			return eventType.getId(); 
		case 1:
			return eventType.getName();
		}
		return ""; // should never get here
	}

	public int getRowCount() {
		if (displayList != null)
		{
			return displayList.size();
		}
		else
		{
			return 0;
		}
	}
	
	public Class<?> getColumnClass(int c) {
        return String.class;
    }

	public boolean isCellEditable(int row, int column) {
		return false;
	}

	public void updateData(ArrayList<EventType> allMembers) {
		displayList = new ArrayList<EventType>(allMembers);
		fireTableDataChanged();
	}

	public EventType getEventType(int row) {
		return displayList.get(row);
	}	
}
